package com.zzhardy.example.sheetExample;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.zzhardy.utils.poi.ExcelCenter;
import cn.zzhardy.utils.poi.utils.UrlUtils;
import cn.zzhardy.utils.result.AjaxResult;
import com.zzhardy.example.common.SysDept;
import com.zzhardy.example.common.SysLog;
import com.zzhardy.example.common.SysUser;
import com.zzhardy.example.sheetExample.model.MoreSheet;
import com.zzhardy.example.sheetExample.model.SingleSheet;
import org.junit.Test;

/**
 * @Author：Hardy
 * @Date：2021/3/27
 * @Function:
 */
public class SheetExample {
    
    
    @Test
    public void moreSheet() {
        List<SysLog>  list     = new ArrayList<>();
        List<SysUser> userlist = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            SysDept sysDept = new SysDept();
            sysDept.setDeptName("测试部门" + 1);
            sysDept.setLeader("测试部门领导" + i);
            setSysLog(list, i);
            setUserData(sysDept, userlist, i);
        }
        MoreSheet moreSheet = new MoreSheet();
        moreSheet.setLogList(list);
        moreSheet.setSysUsers(userlist);
        moreSheet.setLogWarnList(list);
        
        ExcelCenter<MoreSheet> util = new ExcelCenter<>(MoreSheet.class);
        AjaxResult             form = util.exportExcel(moreSheet, "系统测试");
        System.out.println(form.toString());
    }
    
    @Test
    public void singleSheet() {
        List<SysLog>  list     = new ArrayList<>();
        List<SysUser> userlist = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            SysDept sysDept = new SysDept();
            sysDept.setDeptName("测试部门" + 1);
            sysDept.setLeader("测试部门领导" + i);
            setSysLog(list, i);
            setUserData(sysDept, userlist, i);
        }
        SingleSheet singleSheet = new SingleSheet();
        singleSheet.setLogList(list);
        singleSheet.setSysUsers(userlist);
        singleSheet.setLogWarnList(list);
        
        ExcelCenter<SingleSheet> util = new ExcelCenter<>(SingleSheet.class);
        AjaxResult             form = util.exportExcel(singleSheet, "系统测试");
        System.out.println(form.toString());
    }
    
    /**
     * 设置日子数据
     */
    public void setSysLog(List<SysLog> list, int i) {
        SysLog sysLog = new SysLog();
        sysLog.setExceptionInfo("测试");
        sysLog.setJobLogId(i);
        sysLog.setJobMessage("ce111");
        if (i % 2 == 0) {
            sysLog.setStatus(1);
        } else {
            sysLog.setStatus(0);
        }
        sysLog.setCreateDate(new Date());
        String imageUrl = UrlUtils.projectUrl() + "webapp/images/timg.jpg";
        sysLog.setErrorImageUrl(imageUrl);
        list.add(sysLog);
    }
    
    /**
     * 设置用户数据
     */
    public void setUserData(SysDept sysDept, List<SysUser> userlist, int i) {
        SysUser sysUser = new SysUser();
        sysUser.setDept(sysDept);
        sysUser.setNickName("n昵称");
        sysUser.setUserName("dsds");
        userlist.add(sysUser);
    }
}
